<!-- BEGIN Page -->
<html>
<head>
<title>eLGU - {TITLE}</title>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">

<script language="JavaScript" type="text/JavaScript">
<!--




function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//-->
</script>
<link href="../css/elgu.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/JavaScript">
<!--

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</head>
<body BGCOLOR=#999999 link="#333333" vlink="#333333" alink="#333333" LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
  <tr> 
    <td align="center" valign="top"> 
      <table WIDTH=100 BORDER=0 align="center" CELLPADDING=0 CELLSPACING=0>
        <tr> 
          <td> <img SRC="../images/inner_01.jpg" WIDTH=18 HEIGHT=9 ></td>
          <td> <img SRC="../images/inner_02.jpg" WIDTH=27 HEIGHT=9 ></td>
          <td COLSPAN=2> <img SRC="../images/inner_03.jpg" WIDTH=598 HEIGHT=9 ></td>
          <td COLSPAN=3 ROWSPAN=2><img SRC="../images/steps/step00.jpg" WIDTH=157 HEIGHT=133 ></td>
        </tr>
        <tr> 
          <td> <img SRC="../images/inner_05.jpg" WIDTH=18 HEIGHT=124 ></td>
          <td> <img SRC="../images/inner_06.jpg" WIDTH=27 HEIGHT=124 ></td>
          <td COLSPAN=2 bgcolor="#CCCCCC"> <img SRC="../images/title/title_am_trans_gr.jpg" WIDTH=598 HEIGHT=124 ></td>
        </tr>
        <tr> 
          <td> <img SRC="../images/inner_08.jpg" WIDTH=18 HEIGHT=53 ></td>
          <td> <img SRC="../images/inner_09.jpg" WIDTH=27 HEIGHT=53 ></td>
          <td COLSPAN=3 align="left" valign="top" bgcolor="#CCCCCC"> 
            <table WIDTH=702 BORDER=0 CELLPADDING=0 CELLSPACING=0>
	   <tr> 
		<td width="72"> <img SRC="../images/nav/nav_a_01.jpg" WIDTH=72 HEIGHT=53 ></td>
		<td background="../images/nav_area_bg.jpg"><table width="100%%" border="0" cellspacing="0" cellpadding="0">
		  <tr align="center"> 
		   <td width="0" align=left class="common" colspan=4><b>{uname}</b> : {today}</td>
		   <td width="0" align=right colspan=7>
			<a href="home.php{Session}" class="navi" title="Admin Home">Admin Home</a>
		    <font class="navi">&lt;</font>
			<a href="../home.php{Session}" class="navi" title="Home">Home</a>
		    <font class="navi">|</font>
			<a href="../Logout.php" class="navi" title="Logout">Logout</a>
			<br>&nbsp;
		   </td>
		  </tr>

		  <tr align="center"> 
		   <td width="0"><a href="eRPTSSettingsEncode.php{Session}" class="navi" title="eRPTS Settings">eRPTS Settings</a></td>
		   <td width="0" class="navi">|</td>
		   <td width="0"><a href="UserList.php{Session}" class="navi" title="Users List">Users</a></td>
		   <td width="0" class="navi">|</td>
		   <td width="0"><a href="MasterAddressList.php{Session}" class="navi" title="Location"">Location</a></td>
		   <td width="0" class="navi">|</td>
		   <td width="0"><a href="MasterPropertyList.php{Session}" class="navi" title="Property">Property</a></td>
		   <td width="0" class="navi">|</td>
		   <td width="0"><a href="GeneralRevision.php{Session}" class="navi" title="General Revision">General Revision</a></td>
		   <td width="0" class="navi">|</td>
		   <td width="0"><a href="../../nccsms/home.php{Session}" class="navi" title="Alerts">Alerts</a></td>
		  </tr>
		 </table></td>
		<td width="75"> <img SRC="../images/nav/nav_a_08.jpg" WIDTH=75 HEIGHT=53 ></td>
	   </tr>
	  </table>
          </td>
          <td> <img SRC="../images/inner_11.jpg" WIDTH=36 HEIGHT=53 ></td>
          <td> <img SRC="../images/inner_12.jpg" WIDTH=17 HEIGHT=53 ></td>
        </tr>
        <tr> 
          <td align="center" valign="top"> <img SRC="../images/inner_13.jpg" WIDTH=18 HEIGHT=375 ></td>
          <td background="../images/inner_14.jpg"> <img SRC="../images/spacer.gif" WIDTH=27 HEIGHT=1 ></td>
          <td COLSPAN=3 align="left" valign="top" background="../images/background/bg_middle.jpg" bgcolor="#CCCCCC"> 
            <table width="702" height="375" border="0" cellpadding="0" cellspacing="0">
              <tr> 
                <td align="left" valign="top"> 
                  <table width="90%" border="0" cellspacing="0" cellpadding="0" align="center">
                    <tr> 
                      <td align="center" valign="top" class="subtitle"> 
                        <table width="90%" border="0" cellspacing="0" cellpadding="0">
                          <tr> 
							  <td class="subtitle" align="center"><br>General Revision</td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                    <tr> 
                      <td align="center" valign="top" class="title"><img src="../images/spacer.gif" width="10" height="15"></td>
                    </tr>
                    <tr> 
                      
					   <td align="center" valign="top" class="fields">

					   <font color="#990000"><b>{message}</b></font>

					   <br>

					   <!-- BEGIN Done -->
					   <br>
					   <B>Barangay :</B> <font class="subtitle"><B>{barangay}</B></font>
					   <br><br>

					   <B>RPUs Archived :</B> {totalArchived}
					   <br>
					   <B>RPUs Created :</B> {totalCreated}
					   <br><br>

					   <form name="GeneralRevision" action="" method="post">
					   <script language="Javascript">
						function barangayForm(){
							window.location.href = "GeneralRevision.php{Session}";
						}
					   </script>

						   <font size="1" face="verdana">Progress Log (feel free to copy and paste to a txt file for your reference)</font><br>
						   <textarea name="progressLog" rows="4" cols="70" readonly>General Revision Log for barangay : {barangay}
Date: {today}
Started: {timerStart} | Ended: {timerEnd} | Duration: {duration}
-----------------------------------------------------------------------------
{progressLog}</textarea>

						   <br><br>

					   <input type="button" value="RUN ANOTHER BARANGAY" onClick="barangayForm();">
					   </form>
					   <br><br>
					   <!-- END Done -->

					   <!-- BEGIN Confirm -->
					   <br><br>
					   <script language="Javascript">
						// prevent users from coming "back" to this instance of the page
						window.history.forward(1);
					   </script>
					   <B>Barangay :</B> <font class="subtitle"><B>{barangay}</B></font>
					   <br><br>
					   <B>Latest Active RPUs for Barangay:</B> <B>{latestActiveRPUs}</B>
					   <br>
					   <font size="1" face="verdana">(RPUs that have not undergone General Revision in the past {countBackDays} days)</font>
					   <br><br>

					    <form name="GeneralRevision" action="GeneralRevision.php{Session}" method=post>
						   <!-- BEGIN AjaxConfirm -->

						   <script language="Javascript">
						    var ttlArchived;
							var ttlCreated;
							var progressCounter;
							var startTime;
							var endTime;

							function redirectToDonePage(msg){
								doc = document.GeneralRevision;

								timenow = new Date();
								endTime = timenow.toGMTString();
								document.GeneralRevision.timerEnd.value = endTime;

								doc.formAction.value = "done";
								doc.message.value = msg;
								doc.totalArchived.value = ttlArchived;
								doc.totalCreated.value = ttlCreated;

								doc.submit();
								//window.location.href = url;
							}

							function incrementProgressCounter(){
								progressCounter++;
								return progressCounter;
							}
	
							function incrementTotalCreated(increment,totalRPUs){
								if(increment==true){
									ttlArchived++;
									ttlCreated++;
								}

								if(totalRPUs==progressCounter){
									timerStart = false;
									if(ttlCreated==0){
										message = "There were no RPUs generated through General Revision for this barangay.";
									}
									else if(ttlCreated < totalRPUs){
										message = "General Revision partially generated for this barangay!";
									}
									else{
										message = "General Revision successfully generated for this barangay!";
									}
									redirectToDonePage(message);
								}
							}
	
							function runGeneralRevision(){
								confirmRun = confirm("Run General Revision?");
								if(confirmRun){
									timenow = new Date();
									startTime = timenow.toGMTString();
									document.GeneralRevision.timerStart.value = startTime;
	
									document.GeneralRevision.formButton.value = "Please wait...";
									document.GeneralRevision.formButton.disabled = true;
									document.GeneralRevision.previousButton.disabled = true;
									doXHRGeneralRevision();
								}
							}
							function barangayForm(){
								window.location.href = "GeneralRevision.php{Session}";
							}
	
							function doXHRGeneralRevisionForRPU(odID,totalRPUs,odIDArray){
								var xhr;
								var doc;
								var percentage;
								var percentageStr;
								var counter;
	
								doc = document.GeneralRevision;
	
							    // Mozilla version
							    if (window.XMLHttpRequest) {
							        xhr = new XMLHttpRequest();
							    }
							    // IE version
							    else if (window.ActiveXObject) {
							        xhr = new ActiveXObject("Microsoft.XMLHTTP");
							    }
	
								xhr.open("GET","GeneralRevision_AjaxMethods.php?xhrmd5=522eccdf204510a481ca4977d023cf89&formAction=run&odID="+odID+"&userID={userID}");
								xhr.onreadystatechange=function() {
							     if (xhr.readyState==4) {
	
									counter = incrementProgressCounter();
									// compute progress percentage
									percentage = (100 * counter)/totalRPUs;
									percentage = Math.round(percentage);
	
									// add prefix 'zero'
									if(percentage < 10){
										percentageStr = "00" + percentage;								
									}
									else if(percentage < 100){
										percentageStr = "0" + percentage;
									}
									else{
										percentageStr = percentage;
									}
	
									newODID = xhr.responseText;
									if(isNaN(newODID) || newODID==""){
										// if error message is returned from the php
										doc.progressStatus.value = "["+counter+"/"+totalRPUs+" ("+percentageStr+"%)]..."+"[(skipped odID:"+odID+") "+newODID+"]";
										doc.progressLog.value = doc.progressStatus.value + "\n" + doc.progressLog.value;
	
										incrementTotalCreated(false,totalRPUs);
									}
									else{
										doc.progressStatus.value = "["+counter+"/"+totalRPUs+" ("+percentageStr+"%)]..."+"[archived odID:"+odID+" | created odID:"+newODID+"]";
										doc.progressLog.value = doc.progressStatus.value + "\n" + doc.progressLog.value;
										incrementTotalCreated(true,totalRPUs);
									}
	
									doXHRGeneralRevisionAgain(odIDArray);
								 }
								}	
								xhr.send(null);
								return true;
							}

							function doXHRGeneralRevision(){
								var xhr;
								var doc;
								var progresstable;
								var message;
	
								// show progress 'meter'
								progresstable = document.getElementById("progressmeter");
								progresstable.style.display='';
	
								doc = document.GeneralRevision;
	
							    // Mozilla version
							    if (window.XMLHttpRequest) {
							        xhr = new XMLHttpRequest();
							    }
							    // IE version
							    else if (window.ActiveXObject) {
							        xhr = new ActiveXObject("Microsoft.XMLHTTP");
							    }
	
								xhr.open("GET","GeneralRevision_AjaxMethods.php?xhrmd5=522eccdf204510a481ca4977d023cf89&formAction=list&barangayID={barangayID}&countBackDaysTimeStr={countBackDaysTimeStr}");
								xhr.onreadystatechange=function() {
							     if (xhr.readyState==4) {
									// get odID's
									odIDCSV = xhr.responseText;
									odIDArray = odIDCSV.split(",");
									doc.progressStatus.value = "RPUs gathered...";
									doc.progressLog.value += "\n" + doc.progressStatus.value;
	
									ttlArchived = 0;
									ttlCreated = 0;
									progressCounter = 0;
	
									if(odIDCSV==""){
										message = "There were no RPUs generated through General Revision for this barangay.";
										doc.progressStatus.value = "Zero RPUs generated.";
										doc.progressLog.value += "\n" + doc.progressStatus.value;
										redirectToDonePage(message);
									}
									else{
										doXHRGeneralRevisionAgain(odIDArray);
										/* newer method that calls GeneralRevision_AjaxMethods.php sloowly per every half second */
										//timerStart = true;
										//timerID = setTimeout("updateTimer(odIDArray);",500);
	
										/* old method that calls GeneralRevision_AjaxMethods.php in a really really fast loop
										for(i = 0 ; i < odIDArray.length ; i++){
											odID = odIDArray[i];
											doXHRGeneralRevisionForRPU(odID,odIDArray.length);
										}
										*/
									}
								 }
								}	
								xhr.send(null);
							}
	
							function doXHRGeneralRevisionAgain(odIDArray){
								if(progressCounter==odIDArray.length){
									return false;
								}
								else{
									odID = odIDArray[progressCounter];
									doXHRGeneralRevisionForRPU(odID,odIDArray.length,odIDArray);
								}
							}
						   </script>
	
						   <input type="hidden" name="timerStart" value="">
						   <input type="hidden" name="timerEnd" value="">
						   <input type="hidden" name="message" value="">
						   <input type="hidden" name="totalArchived" value="">
						   <input type="hidden" name="totalCreated" value="">
						   <input type="hidden" name="barangayID" value="{barangayID}">
		   				   <input type="hidden" name="formAction" value="run">
						   <input type="button" name="previousButton" value="&lt; Previous" onClick="barangayForm();">
					   	   <input type="button" name="formButton" value="Run" onClick="runGeneralRevision();">
	
						   <table border="0" style="display:none;" id="progressmeter" align="center">
						   <tr>
							<td align="center">
								<font face="verdana" size="1">
								Progress Status:<br>
								<input type="text" name="progressStatus" value="gathering RPUs..." size="70" disabled style="text-align:center;">
								<br>
								Progress Log:<br>
								<textarea name="progressLog" rows="4" cols="70" readonly></textarea>
								</font>
							</td>
						   </tr>
						   </table>

						   <!-- END AjaxConfirm -->

						   <!-- BEGIN ConventionalConfirm -->

						   <script language="Javascript">

							function runGeneralRevision(){
								confirmRun = confirm("Run General Revision?");
								if(confirmRun){
									timenow = new Date();
									startTime = timenow.toGMTString();
									document.GeneralRevision.timerStart.value = startTime;

									document.GeneralRevision.formButton.value = "Please wait...";
									document.GeneralRevision.formButton.disabled = true;
									document.GeneralRevision.previousButton.disabled = true;

									document.GeneralRevision.submit();
								}
							}
							function barangayForm(){
								window.location.href = "GeneralRevision.php{Session}";
							}

						   </script>

						   <input type="hidden" name="countBackDaysTimeStr" value="{countBackDaysTimeStr}">
						   <input type="hidden" name="barangayID" value="{barangayID}">
						   <input type="hidden" name="timerStart" value="">
		   				   <input type="hidden" name="formAction" value="run">
						   <input type="button" name="previousButton" value="&lt; Previous" onClick="barangayForm();">
  					   	   <input type="button" name="formButton" value="Run" onClick="runGeneralRevision();">
						   <!-- END ConventionalConfirm -->
						</form>
					   <!-- END Confirm -->

					   <!-- BEGIN BarangayForm -->
					   <br>

					   <form name="GeneralRevision" action="GeneralRevision.php{Session}" method="post">
							<input type="hidden" name="formAction" value="confirmAjax">

							<input type="hidden" name="countBackDays" value="{countBackDays}">
							<input type="hidden" name="countBackDaysTimeStr" value="{countBackDaysTimeStr}">

					   List of Barangays
					   <br><br>

					   <script language="Javascript">
						   function confirmBarangay(){
								doc = document.GeneralRevision;
								if(doc.barangayID.selectedIndex > 0){
									if(doc.ajaxCheck.checked==true){
										// performs general revision asynchronously using ajax
										doc.formAction.value = "confirmAjax";
									}
									else{
										// performs general revision in one big server process
										doc.formAction.value = "confirm";
									}

									doc.submit();
								}
						   }
					   </script>

							<select name="barangayID" style="font-size:10px; width=175;" size="10" onChange="getXHRBarangayCountForOption();">
							    <option value=""></option>
								<!-- BEGIN BarangayList -->
								<option value="{barangayID}" {barangayID_sel}>{barangay}</option>
								<!-- END BarangayList -->
							</select>

							<br><br>

							<input type="button" name="nextButton" value="Next >" onClick="confirmBarangay();" checked>

							<br><br>

						   <table border="0" cellpadding="1" cellspacing="0"><tr><td bgcolor="#333333">
						   <table border="0" cellpadding="2" cellspacing="0" width="100%">
						   <tr>
							<td bgcolor="#f6f6f6" valign="top">
								<font face="verdana" size="1">
							   <input type="checkbox" name="countCheck" checked> Count RPUs for Barangay when selected?
							   </font>
							</td>
						   </tr>
						   <tr>
							<td bgcolor="#f6f6f6" valign="top">
								<font face="verdana" size="1">
							   <input type="checkbox" name="ajaxCheck" checked> Asynchronous General Revision processing?
							   </font>
							</td>
						   </tr>
						   </table>
						   </td></tr></table>

					   </form>

					   <!-- BEGIN AjaxBarangayForm -->
					   <script language="Javascript">
						// ajax experiment

						function getXHRBarangayCount(b){
							var xhr;
							var doc;

							doc = document.GeneralRevision;
							doc.nextButton.disabled = true;
							doc.barangayID.disabled = true;

						    // Mozilla version
						    if (window.XMLHttpRequest) {
						        xhr = new XMLHttpRequest();
						    }
						    // IE version
						    else if (window.ActiveXObject) {
						        xhr = new ActiveXObject("Microsoft.XMLHTTP");
						    }

							// bID stores the barangayID value
							bID = doc.barangayID.options[b].value;
							xhr.open("GET","GeneralRevision_AjaxMethods.php?xhrmd5=522eccdf204510a481ca4977d023cf89&formAction=count&barangayID="+bID+"&countBackDaysTimeStr={countBackDaysTimeStr}");
							xhr.onreadystatechange=function() {
						     if (xhr.readyState==4) {
								txt = xhr.responseText;
								doc.barangayID.options[b].text = txt;
								doc.nextButton.disabled = false;
								doc.barangayID.disabled = false;
							 }
							}	
							xhr.send(null);
						}

						function getXHRBarangayCountForOption(){
							doc = document.GeneralRevision;
							if(doc.countCheck.checked==false){
								return false;
							}

							if(doc.barangayID.selectedIndex > 0){
								optionText = doc.barangayID.options[doc.barangayID.selectedIndex].text;
								if(optionText.indexOf("(")==-1 && optionText.indexOf(")")==-1){
									getXHRBarangayCount(doc.barangayID.selectedIndex);
								}
							}
						}
					   </script>
					   <!-- END AjaxBarangayForm -->

					   <!-- END BarangayForm -->

						</td>
                    </tr>
                    <tr> 
                      <td align="center" valign="top"><img src="../images/spacer.gif" width="10" height="15"><a name="#down"></a></td>
                    </tr>
                    <tr> 
                      <td align="center" valign="top" class="fileds_comment">
					    <br><br><br><br><br><br><br><br><br><br><br><br><br><br>
						Tampering 
                        with this system is criminally punishable under Philippine 
                        Laws.<br>
                        &copy; Republic of the Philippines National Computer Center. 
                        All Rights Reserved. </td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
          <td background="../images/inner_16.jpg"> <img SRC="../images/spacer.gif " WIDTH=36 HEIGHT=375 ></td>
          <td> <img SRC="../images/inner_17.jpg" WIDTH=17 HEIGHT=375 ></td>
        </tr>
        <tr> 
          <td> <img SRC="../images/inner_18.jpg" WIDTH=18 HEIGHT=39></td>
          <td> <img SRC="../images/inner_19.jpg" WIDTH=27 HEIGHT=39></td>
          <td> <img SRC="../images/inner_20.jpg" WIDTH=355 HEIGHT=39></td>
          <td> <img SRC="../images/inner_21.jpg" WIDTH=243 HEIGHT=39></td>
          <td> <img SRC="../images/inner_22.jpg" WIDTH=104 HEIGHT=39></td>
          <td> <img SRC="../images/inner_23.jpg" WIDTH=36 HEIGHT=39></td>
          <td> <img SRC="../images/inner_24.jpg" WIDTH=17 HEIGHT=39></td>
        </tr>
      </table>
    </td>
  </tr>
</table>

</body>
</html>
<!-- END Page -->

<!-- BEGIN Run -->
<html><body>

					    <form name="GeneralRevision" action="GeneralRevision.php{Session}" method=post>
						   <input type="hidden" name="timerStart" value="{timerStart}">
						   <input type="hidden" name="timerEnd" value="{timerEnd}">
						   <input type="hidden" name="message" value="{message}">
						   <input type="hidden" name="totalArchived" value="{totalArchived}">
						   <input type="hidden" name="totalCreated" value="{totalCreated}">
						   <input type="hidden" name="barangayID" value="{barangayID}">
						   <input type="hidden" name="progressLog" value="{progressLog}">
		   				   <input type="hidden" name="formAction" value="done">

						   <script language="Javascript">
								// prevent users from coming "back" to this instance of the page
								window.history.forward(1);
								document.GeneralRevision.submit();
						   </script>
						</form>
</body></html>
<!-- END Run -->